import 'package:basic/basic.dart';
import 'package:core/core.dart';
import 'package:flutter/material.dart';

import '../constant.dart';

const String loginStatusChangeKey = "loginStatusChange"; //登录状态改变
//登录状态改变监听
mixin LoginStatusChangeMixin<T extends StatefulWidget> on State<T> {
  @override
  void initState() {
    super.initState();
    LogUtil.v(
      "LoginStatusChangeMixin(${widget.toStringShort()}) 注册登录状态监听 --->",
    );
    _registerLoginStatusChange();
  }

  //登录状态改变监听
  _registerLoginStatusChange() {
    bus.on(loginStatusChangeKey, (isLogin) {
      if (isLogin != null && isLogin is bool) {
        loginStatusChange(isLogin);
      }
    });
  }

  //登录状态改变 回调方法
  void loginStatusChange(bool isLogin);

  @override
  void dispose() {
    super.dispose();
    LogUtil.v(
      "LoginStatusChangeMixin(${widget.toStringShort()}) 注销登录状态监听 --->",
    );
    bus.off(loginStatusChangeKey);
  }
}
